import 'package:ati_package/core/extension/ati_widgets_extension.dart';
import 'package:ati_package/pages/common/ati_scaffold.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_form_builder/flutter_form_builder.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import '../../../../core/utils/ati_color.dart';
import '../../../../core/utils/ati_font.dart';
import '../../../common/widgets/ati_text_input.dart';

class PasswordLoginView extends StatefulWidget {
  const PasswordLoginView({super.key});

  @override
  State<PasswordLoginView> createState() => _PasswordLoginViewState();
}

class _PasswordLoginViewState extends State<PasswordLoginView> {
  final _formKey = GlobalKey<FormBuilderState>();

  @override
  Widget build(BuildContext context) {
    return AtiScaffold(
      title: '修改登录密码',
      body: Column(children: [_buildTextInput(), _buildFootbtn()]),
    );
  }

  _buildTextInput() {
    return Container(
      padding: EdgeInsets.only(top: 20.r, left: 16.r, right: 16.r),
      child: FormBuilder(
        key: _formKey,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            AtiTextInput(
              name: 'oldPassword',
              label: '旧登录密码',
              hint: '请输入旧密码',
              obscureText: true,
              showObscureToggle: true,
              validator: (val) => val == null || val.isEmpty ? '请输入旧密码' : null,
            ),
            AtiTextInput(
              name: 'newPassword',
              label: '新登录密码',
              hint: '请输入新密码',
              obscureText: true,
              showObscureToggle: true,
              validator: (val) => val == null || val.isEmpty ? '请输入新密码' : null,
            ),
            AtiTextInput(
              name: 'newPassword',
              label: '确认新密码',
              hint: '请再次输入新密码',
              obscureText: true,
              showObscureToggle: true,
              validator: (val) => val == null || val.isEmpty ? '请输入新密码' : null,
            ),
          ],
        ),
      ),
    );
  }

  _buildFootbtn() {
    return Container(
      height: 40.r,
      alignment: Alignment.center,
      margin: EdgeInsets.only(left: 50.r, right: 50.r, top: 50.r),
      decoration: BoxDecoration(
        gradient: AtiColor.primaryGradient,
        borderRadius: BorderRadius.circular(20.r),
      ),
      child: Text(
        '提交',
        style: TextStyle(
          color: AtiColor.textHLColor1,
          fontSize: AtiFont.font14,
        ),
      ),
    ).addTapGesture(onTap: () {});
  }
}
